import { Component, OnInit, Input } from "@angular/core";
import { AppGlobalService } from "src/app/shared/service/app-global.service";
import { HttpService } from '../../shared/service/http.service';
@Component({
  selector: "app-inner-title",
  templateUrl: "./inner-title.component.html",
  styleUrls: ["./inner-title.component.scss"]
})
export class InnerTitleComponent implements OnInit {
  @Input() tagData: any; // 标签数据
  cssStr = {}; // 传入样式

  constructor(private appGlobalService: AppGlobalService, private http: HttpService) { }

  ngOnInit() {
    // this.cssStr = this.tagData.data.cssStyle;
  }

  //  跳转页面
  go(obj) {
    const pageParams = {
      pageId: obj.target,
      params: obj.params,
      sessionId: localStorage.getItem("sessionId")
    };
    // 根据type的不同去跳转不同的服务协议页面
    if (this.tagData.data.button.link.type === 'contract') {
      this.http.post('element/serviceContract/url', pageParams.params, res => {
        this.appGlobalService.openUrl(this.tagData.data.button.label, res.url, obj.target, JSON.stringify(obj.params));
      });
      // tslint:disable-next-line: max-line-length
    } else if (this.tagData.data.button.link.type === "decoration" || this.tagData.data.button.link.type === "projectInv" || this.tagData.data.button.link.type === "propertyInv") {
      const type = { type: this.tagData.data.button.link.type };
      pageParams.params = Object.assign(
        pageParams.params,
        type
      );
      this.http.post('element/serviceContract/decorationurl', pageParams.params, res => {
        this.appGlobalService.openUrl(obj.label, res.url, obj.target, JSON.stringify(obj.params));
      });
    } else {
      this.appGlobalService.goToForward(pageParams);
    }
  }
}
